package com.bigflexlib.ds.container.bag.impl
{
	
	import com.bigflexlib.ds.container.IRContainer;
	import com.bigflexlib.ds.container.bag.IRWBag;
	import com.bigflexlib.ds.container.impl.AbstractRWDictionaryContainer;


	public class RWDictionaryBag extends AbstractRWDictionaryContainer implements IRWBag
	{
	
	
		/**
		 * 
		 * 
		 * 
		 * @param source
		 * 		an Array or IRContainer with data to instantiate this Bag
		 * 
		 */
		public function RWDictionaryBag( source:* = null )
		{
		
			if ( source is Array )
			{
				var arr:Array = source as Array;
				for each ( var e:* in arr )
				{
					add( e, 1 );				
				}
			}
			else if ( source is IRContainer )
			{
				var c:IRContainer = source as IRContainer;
				c.walk( function( e:*, m:int ):void{
						add( e, m );
					} );			
			}
		
		}	
	
	
	
	
	
	
	
	
	

		public function add( e:*, delta:int ):void
		{
			m( e, delta );
		}
		
		
		public function setMultiplicity( e:*, absoluteMultiplicity:uint ):void
		{

			// TODO: this could be optimized
			// the base class should surface another method
			m( e, absoluteMultiplicity - getMultiplicity( e ) );			
				
		}
		
		
	
	}
	

}